<%-- 
    Document   : manage_list
    Created on : Oct 21, 2011, 5:53:08 PM
    Author     : Yudi Retanto
--%>

<%@page import="com.moedik.classes.ShuttleService"%>
<%@page import="com.moedik.model.ShuttleModel"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <tr>
        <script type="text/javascript">
    function deleteSchedule(id,obj){
        var answer = confirm("Apakah ingin menghapus jadwal ini?");
        if (answer){
            var parent = $(obj).parent().parent();
            $.ajax({
                type: 'get',
                url: 'shuttles',
                data: 'action=manage&mode=delete&schedule=' + id,
                beforeSend: function() {
                    parent.fadeTo('slow', 0.25);
                },
                success: function() {
                    parent.find('td').wrapInner('<div style="display: block;" />').parent().find('td > div').slideUp(300, function() {
                        parent.remove();
                    });
                },
                error: function() {
                    parent.stop().fadeTo('slow', 1);
                }
            });
        }
    }
</script>
        <th class="td-no">No</th>
        <th>Kota Tujuan</th>
        <th>Pool Tujuan</th>
        <th>Kelas</th>
        <th>Hari Keberangkatan</th>
        <th>Jam</th>
        <th>Harga</th>
        <th>Action</th>
    </tr>
    <c:forEach items="${schedules}" var="schedule">
        <c:set var="service_day" value="${schedule.day}" />
        <%
            String day = (String) pageContext.getAttribute("service_day");
            day = day.replace("1", "Sun");
            day = day.replace("2", "Mon");
            day = day.replace("3", "Tue");
            day = day.replace("4", "Wed");
            day = day.replace("5", "Thu");
            day = day.replace("6", "Fri");
            day = day.replace("7", "Sat");
        %>
        <c:set var="ordinal" value="${ordinal + 1}" />
        <tr id="record-${schedule.id}">
            <td class="td-no">${ordinal}</td>
            <td>${schedule.destinationCity}</td>
            <td>${schedule.destinationPool}</td>
            <td>${schedule.className}</td>
            <td>
                <% out.print(day);%>
            </td>
            <td>${schedule.hour}</td>
            <td>${schedule.fare}</td>
            <td>
                <a href="./shuttles?action=manage&mode=edit&schedule=${schedule.id}">Edit</a>
                <a href="#" onclick="deleteSchedule(${schedule.id},this)">Delete</a>
            </td>
        </tr>
    </c:forEach>
